package servlet;

import entity.Booking;
import service.BookingService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/AddServlet")
public class AddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        BookingService service = new BookingService();
        Booking book = new Booking();
        book.setUserName(request.getParameter("userName"));
        book.setCardId(request.getParameter("cardId"));
        book.setStatus(0);
        book.setBookingDate(request.getParameter("bookingDate"));
        int count = service.add(book);
        if (count>0){
            request.setAttribute("info","添加成功！");
        }else {
            request.setAttribute("info","添加失败！！！");
        }
        request.getRequestDispatcher("ListServlet").forward(request,response);
    }
}
